﻿#include "FITKAbaInteractionSurfToSurfExplicit.h"


Interface::FITKAbaAbstractInteraction::FITKAbaInteractionType Interface::FITKAbaInteractionSurfToSurfExplicit::getInteractionType() const
{
    return FITKAbaAbstractInteraction::FITKAbaInteractionType::SurfToSurfContactExplicit;
}

bool Interface::FITKAbaInteractionSurfToSurfExplicit::copy(FITKAbstractDataObject *obj)
{
    bool ok = FITKAbaAbstractInteraction::copy(obj);
    if (!ok)
        return false;
    FITKAbaInteractionSurfToSurfExplicit* s = dynamic_cast<FITKAbaInteractionSurfToSurfExplicit*>(obj);
    if (s == nullptr)
        return false;
    m_machanicalConsForm = s->m_machanicalConsForm;
    this->m_uniformClearance = s->m_uniformClearance;
    this->m_initialClearance = s->m_initialClearance;
    this->m_contactPropertyId = s->m_contactPropertyId;
    this->m_sliding = s->m_sliding;
    this->m_weightingFactor = s->m_weightingFactor;
    this->m_weightingFactorValue = s->m_weightingFactorValue;
    return true;
}


bool Interface::FITKAbaInteractionSurfToSurfExplicit::isModifiedInStep(int stepId) const
{
    //根据后续分析步数据判断是否修改
    if (stepId <= 0 || stepId == m_createdStepId)
        return false;
    if (m_modifiedDatas.contains(stepId))
        return true;
    return false;
}

void Interface::FITKAbaInteractionSurfToSurfExplicit::activeStateChanged()
{
    //清理数据
    if (m_deactiveStepId == -1)
        return;
    //访问当前算例的分析步管理器，获取分析步顺序id列表。
    QVector<int> stepIds = this->getStepIds();
    int index = stepIds.indexOf(m_deactiveStepId);
    if (index == -1)
        return;
    for (int i = index ; i < stepIds.count(); ++i)
    {
        int id = stepIds[i];
        if (m_modifiedDatas.contains(id))
            m_modifiedDatas.remove(id);
    }
}

namespace Interface {

    FITKAbaInteractionSurfToSurfExplicit::MachanicalConstraintFormulation FITKAbaInteractionSurfToSurfExplicit::getMachanicalConstraintFormulation() const
{
    return m_machanicalConsForm;
}

void FITKAbaInteractionSurfToSurfExplicit::setMachanicalConstraintFormulation(FITKAbaInteractionSurfToSurfExplicit::MachanicalConstraintFormulation newMachanicalConsForm)
{
    m_machanicalConsForm = newMachanicalConsForm;
}

FITKAbaAbstractInteraction::SlidingFormulation FITKAbaInteractionSurfToSurfExplicit::getSlidingFormulation() const
{
    return m_sliding;
}

void FITKAbaInteractionSurfToSurfExplicit::setSlidingFormulation(SlidingFormulation newSliding)
{
    m_sliding = newSliding;
}

FITKAbaInteractionSurfToSurfExplicit::InitialClearance FITKAbaInteractionSurfToSurfExplicit::getInitialClearance() const
{
    return m_initialClearance;
}

void FITKAbaInteractionSurfToSurfExplicit::setInitialClearance(InitialClearance newInitialClearance)
{
    m_initialClearance = newInitialClearance;
}

double FITKAbaInteractionSurfToSurfExplicit::getUniformClearance() const
{
    return m_uniformClearance;
}

void FITKAbaInteractionSurfToSurfExplicit::setUniformClearance(double newUniformClearance)
{
    m_uniformClearance = newUniformClearance;
}

int FITKAbaInteractionSurfToSurfExplicit::getContactPropertyId(int stepId)
{
    return this->getContactPorpertyIdInStep(stepId);
}

void FITKAbaInteractionSurfToSurfExplicit::setContactPropertyId(int newContactPropertyId, int stepId)
{
    if (stepId <= 0 || stepId == m_createdStepId)
        m_contactPropertyId = newContactPropertyId;
    else
    {
        if (!m_modifiedDatas.contains(stepId))
            m_modifiedDatas[stepId] = this->getContactPorpertyIdInStep(stepId);
        m_modifiedDatas[stepId] = newContactPropertyId;
    }
}

FITKAbaInteractionSurfToSurfExplicit::WeightingFactor FITKAbaInteractionSurfToSurfExplicit::getWeightingFactor() const
{
    return m_weightingFactor;
}

void FITKAbaInteractionSurfToSurfExplicit::setWeightingFactor(WeightingFactor newWeightingFactor)
{
    m_weightingFactor = newWeightingFactor;
}

double FITKAbaInteractionSurfToSurfExplicit::getWeightingFactorValue() const
{
    return m_weightingFactorValue;
}

void FITKAbaInteractionSurfToSurfExplicit::setWeightingFactorValue(double newWeightingFactorValue)
{
    m_weightingFactorValue = newWeightingFactorValue;
}

int FITKAbaInteractionSurfToSurfExplicit::getContactPorpertyIdInStep(int stepId)
{
    if (stepId <= 0 || stepId == m_createdStepId)
        return m_contactPropertyId;
    if (m_modifiedDatas.contains(stepId))
        return m_modifiedDatas[stepId];
    QVector<int> stepIds = this->getStepIds();
    int createdStepIndex = stepIds.indexOf(m_createdStepId);
    int stepIndex = stepIds.indexOf(stepId);
    if (!(createdStepIndex >= 0 && createdStepIndex < stepIds.size()))
        return m_contactPropertyId;
    if (!(stepIndex >= 0 && stepIndex < stepIds.size()))
        return m_contactPropertyId;
    for (int i = stepIndex; i >= createdStepIndex; --i)
    {
        int id = stepIds.at(i);
        if (m_modifiedDatas.contains(id))
            return m_modifiedDatas[id];
    }
    return m_contactPropertyId;
}

}
